import instance from '@/utils/axios.js'
import _ from 'lodash';
let api = {};
let apiFiles =
    import.meta.globEager("../apis/*.js");
// 把所有apis目录下的接口合并到api对象中。
Object.keys(apiFiles).forEach(key => {
    let apiItem = apiFiles[key];
    let oldApis = Object.keys(api);
    let addApis = Object.keys(apiItem);
    api = Object.assign(api, {...apiItem })
    let newApis = Object.keys(api);
    if (oldApis.length + addApis.length > newApis.length) console.error('apis目录下接口重叠。文件', key, ' 重复接口：', _.intersection(oldApis, addApis))
})

// 用法：let data = await this.$api.testApi(20) ;
export default {
    install(app) {
        app.config.globalProperties.$axios = instance
        app.config.globalProperties.$api = api
    }
};